//
//  NumberLimitationViewController.m
//  Socrates
//
//  Created by shy on 15/3/23.
//  Copyright (c) 2015年 shy. All rights reserved.
//

#import "NumberLimitationViewController.h"

#import "RDVTabBarController.h"

typedef enum {
    kLimitation_total_num_item = 0,
    kLimitation_male_num_item,
    kLimitation_female_num_item,
    kLimitation_Num,
} LimitationItems;

static const int kLimitationRowHeight = 36;

static const int kLimitationHeaderHeight = 36;


@interface NumberLimitationViewController ()<UITableViewDelegate, UITableViewDataSource> {
    UITextField *total_;
    UITextField *male_;
    UITextField *female_;
}
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UILabel *hintLimit;
@property (weak, nonatomic) IBOutlet UILabel *hintNoLimit;

@end

@implementation NumberLimitationViewController

- (void)dealloc {
    NSLog(@"%@ dealloc", self.class);
}

- (void) viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.hidden = NO;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.scrollEnabled = NO;
    [self configHintView];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return kLimitationRowHeight;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return kLimitationHeaderHeight;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 25)];
    view.backgroundColor = [UIColor colorWithRed:239/255. green:239/255. blue:244/255. alpha:1.];
    UILabel *hintSetLimit = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, self.view.frame.size.width - 46, kLimitationHeaderHeight)];
    hintSetLimit.backgroundColor = [UIColor clearColor];
    hintSetLimit.font = [UIFont systemFontOfSize:13.];
    hintSetLimit.text = @"设置活动人数上限";
    hintSetLimit.textColor = [UIColor grayColor];
    [view addSubview:hintSetLimit];
    return view;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return kLimitation_Num;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UIEdgeInsets edgeInset = self.tableView.separatorInset;
    self.tableView.separatorInset = UIEdgeInsetsMake(edgeInset.top, 23, edgeInset.bottom, 23);
    NSString *cellIdentifier = @"RegisterCellIdentifier";
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    switch ([indexPath row]) {
        case kLimitation_total_num_item:
            total_ = [[UITextField alloc] initWithFrame:CGRectMake(23, 0, cell.frame.size.width, cell.frame.size.height)];
            total_.placeholder = @"总人数";
            total_.font = [UIFont systemFontOfSize:16.];
            [total_ setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
            [cell addSubview:total_];
            break;
        case kLimitation_male_num_item:
            male_ = [[UITextField alloc] initWithFrame:CGRectMake(23, 0, cell.frame.size.width, cell.frame.size.height)];
            male_.placeholder = @"男生人数";
            male_.font = [UIFont systemFontOfSize:16.];
            [male_ setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
            [cell addSubview:male_];
            break;
        case kLimitation_female_num_item:
            female_ = [[UITextField alloc] initWithFrame:CGRectMake(23, 0, cell.frame.size.width, cell.frame.size.height)];
            female_.placeholder = @"女生人数";
            female_.font = [UIFont systemFontOfSize:16.];
            [female_ setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
            [cell addSubview:female_];
            break;
        default:
            break;
    }
    return cell;
}

- (void)configHintView {
    self.hintLimit.text = @"您可以设置总人数，也可以分别设置男生女生人数上限。";
    self.hintLimit.textColor = [UIColor grayColor];
    self.hintLimit.font = [UIFont systemFontOfSize:12.];
    
    self.hintNoLimit.text = @"若您未填写则显示为人数不限";
    self.hintNoLimit.textColor = [UIColor grayColor];
    self.hintNoLimit.font = [UIFont systemFontOfSize:12.];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated {
    [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];
    
    [super viewWillDisappear:animated];
}

@end
